#!/bin/bash
echo "build start" && \
export CCACHE_BASE="${PWD}" && \
export NODE_HOME=/home/tools/node-v18.17.1-linux-x64 && \
export NO_DEVTOOL=1 && \
export CCACHE_MAXSIZE=20 && \
export PATH=$(pwd)/prebuilts/command-line-tools/hvigor/bin:$(pwd)/prebuilts/command-line-tools/ohpm/bin:${PWD}/prebuilts/build-tools/common/nodejs/node-v16.20.2-linux-x64/bin:$PATH && \
export CCACHE_NOHASHDIR="true" && \
export CCACHE_SLOPPINESS="include_file_ctime" && \
export CCACHE_LOCAL_DIR=.ccache_xts  && \

chmod -R 755 ./prebuilts/command-line-tools
mkdir -p $HOME/.hvigor/wrapper/tools
cat <<EOF > $HOME/.hvigor/wrapper/tools/package.json
{
  "dependencies": {
    "pnpm": "7.30.0"
  }
}
EOF
cd "$HOME/.hvigor/wrapper/tools" 
echo "npminstall"
npm install
if [ $? -eq 0 ]; then
    echo "npmsucceeded"
else
    echo "npmfailed"
    exit 1
fi
cd - || exit
mkdir -p out/hap
applications/standard/hap/build.sh --build_sdk=true --project=$(pwd)/my-test --out_path=$(pwd)/out/hap/my-test.hap
if [[ "$?" -ne 0 ]]; then
  echo -e "\033[31m[OHOS ERROR] hap build failed!\033[0m"
  exit 1
fi
